<?php

/**
 * This is the model class for table "comandalin".
 *
 * The followings are the available columns in table 'comandalin':
 * @property integer $id
 * @property integer $comanda_id
 * @property integer $producte_id
 * @property integer $quantitat
 * @property string $observacions
 *
 * The followings are the available model relations:
 * @property Comanda $comanda
 * @property Producte $producte
 */
class Comandalin extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Comandalin the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'comandalin';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('comanda_id, producte_id, quantitat', 'required'),
			array('comanda_id, producte_id, quantitat', 'numerical', 'integerOnly'=>true),
			array('observacions', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, comanda_id, producte_id, quantitat, observacions', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'liniaComanda' => array(self::BELONGS_TO, 'Comanda', 'comanda_id'),
			'liniaProducte' => array(self::BELONGS_TO, 'Producte', 'producte_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'comanda_id' => 'Comanda',
			'producte_id' => 'Producte',
			'quantitat' => 'Quantitat',
			'observacions' => 'Observacions',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('comanda_id',$this->comanda_id);
		$criteria->compare('producte_id',$this->producte_id);
		$criteria->compare('quantitat',$this->quantitat);
		$criteria->compare('observacions',$this->observacions,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}